/*
 * 导入外部js文件
 */
document.write("<script language=javascript src='/js/common.js'></script>");
var originalSrc= "";
//创建文件读取对象
var reader  = new FileReader();

function modifyNickname(obj){
	
	var op = obj.parentNode;
	var current = document.getElementById("nickname");
	var cp = current.parentNode;
	var textInput = document.createElement("input");
	textInput.type= "text";
	textInput.value = current.innerHTML;
	
	var ensureBtn = document.createElement("Button");
	ensureBtn.type="button";
	ensureBtn.className = "btn-small ensure-btn";
	ensureBtn.innerHTML="确认";
	ensureBtn.onclick=function(){
		
		var nickname = textInput.value;
		if(nickname=="" || isEmptyString(nickname)){
			return ;
		}
		ajax({
			url :　"/user/nickname/modify",
			method : "POST",
			data : "nickname="+ nickname,
			onsuccess : function(text){
				var result = eval("("+text+")");
				if(result.success){
					current.innerHTML = nickname;
					
					op.removeChild(ensureBtn);
					op.removeChild(cancleBtn);
					op.appendChild(obj);
					
					cp.removeChild(textInput);
					cp.appendChild(current);
				}
			}
		});
	}
	
	var cancleBtn = document.createElement("Button");
	cancleBtn.type="button";
	cancleBtn.className = "btn-small cancle-btn";
	cancleBtn.innerHTML="取消";
	cancleBtn.onclick = function(){
		op.removeChild(ensureBtn);
		op.removeChild(cancleBtn);
		op.appendChild(obj);
		
		cp.removeChild(textInput);
		cp.appendChild(current);
	};
	
	op.removeChild(obj);
	op.appendChild(ensureBtn);
	op.appendChild(cancleBtn);
	
	cp.removeChild(current);
	cp.appendChild(textInput);
}

function openImageEditMode(obj){
	
	var form = document.getElementById("form");
	var file = document.getElementById("file");
	file.click();
	form.style.display = "block";
}

function modifyIcon(obj){
	
	var usericon = document.getElementById("usericon");
	originalSrc = usericon.src;
//	添加文件加载事件监听器
	reader.addEventListener("load", function () {
		usericon.src = reader.result;
	}, false);
//	加载文件
	if (obj.files.item(0)) {
	   reader.readAsDataURL(obj.files.item(0));
	}
}

function ensure(){
	
	if(document.getElementById("usericon").src == originalSrc){
		return ;
	}
	document.getElementById("form").submit();
}


function cancle(){
	
	document.getElementById("usericon").src = originalSrc;
	document.getElementById("form").style.display = "none";
	
}



